<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport"
    content="width=device-width,height=device-height,initial-scale=1,minimum-scale=1,user-scalable=no">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>幸运大转盘</title>
  <script src="js/jquery.min.js"></script>
  <script type="text/javascript" src="https://cdn.aodianyun.com/dms/rop_client.js"></script>
  <style>
    * {
      margin: 0;
      padding: 0;
      -webkit-tap-highlight-color: transparent;
    }

    body {
      background-color: rebeccapurple;
    }

    #message {
      text-align: center;
      color: #ffffff;
      font-size: 50px;
    }

    #app {
      max-width: 375px;
      margin: auto;
    }


    .opt {
      font-size: 25px;
      margin-bottom: 25px;
      text-align: center;
      margin-top: 20px;
      color: #ffffff;
    }



    .no-select {
      -webkit-touch-callout: none;
      /* iOS Safari */
      -webkit-user-select: none;
      /* Chrome/Safari/Opera */
      -moz-user-select: none;
      /* Firefox */
      -ms-user-select: none;
      /* Internet Explorer/Edge */
      user-select: none;
      /* Non-prefixed version, currently supported by most modern browsers */
    }

    .btn {
      display: flex;
      flex-wrap: wrap;
      flex-direction: row;
      align-content: flex-start;
      justify-content: flex-start;
      align-items: stretch;
    }

    .btn div {
      border: 1px solid #fff;
      color: #ffffff;
      text-align: center;
      width: 50px;
      height: 50px;
      display: flex;
      flex-wrap: wrap;
      align-content: center;
      flex-direction: row;
      justify-content: center;
      align-items: stretch;
      margin: 10px;
    }

    .selected {
      background-color: red;
    }
  </style>
</head>

<body>
  <div id="app">
    <div class="opt no-select">奖项设置</div>
    <div class="btn">
      <div>1</div>
      <div>2</div>
      <div>3</div>
      <div>4</div>
      <div>5</div>
      <div>6</div>
      <div>7</div>
      <div>8</div>
      <div>9</div>
    </div>
  </div>
  <div>
    <p id="message"></p>
  </div>
  </div>
  <script>

    function getParams (url) {
      const regex = /[?&]([^=#]+)=([^&#]*)/g;
      const params = {};
      let match;
      while (match = regex.exec(url)) {
        params[decodeURIComponent(match[1])] = decodeURIComponent(match[2]);
      }
      return params;
    }

    function generateRandomString (length) {
      const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
      let result = '';
      for (let i = length; i > 0; --i) {
        result += chars[Math.floor(Math.random() * chars.length)];
      }
      return result;
    }

    $(() => {

      var params = getParams(location.href);
      if (params.t !== undefined) {
        var pubkey = 'pub_32389ade98c9ca34ddd2d3d3678ef650'
        var subkey = 'sub_d45ab45c55957c9395adcd266b288ce2'
        var clientid = generateRandomString(16);
        var topic = params.t
        if (window.location.protocol === "https:") {
          ROP.Enter(pubkey, subkey, clientid, true)
        } else {
          ROP.Enter(pubkey, subkey)
        }
        //连接成功
        ROP.On("enter_suc", function () {
          console.log("EnterSuc");
        })
        //连接失败
        ROP.On("enter_fail", function (err) {
          console.log("EnterFail:" + err);
        })
        //离线，以及开始重连的事件
        ROP.On("reconnect", function () {
          console.log("reconnect:");
        })
        ROP.On("offline", function (err) {
          console.log("offline:" + err);
        })
        //收到关注的话题的消息
        ROP.On("publish_data", function (data, topic) {
          console.log("recv at " + topic + " -> " + data);
        })

        $('.btn div').on('click', function () {
          ROP.Publish($(this).text(), topic)
          $(this).addClass('selected');
          $(this).siblings().removeClass('selected');
        })
      }
    })
  </script>

  <div style="text-align:center;margin:50px 0; font:normal 14px/24px 'MicroSoft YaHei';">
  </div>
</body>

</html>